<template>
  <div>
    <div :style="btnStyleComputed" @mouseover="buttonCommonMouseOver($event)" @mouseout="buttonCommonMouseOut($event)"
         class="buttonCommonClass" @click="btnClick">{{btnMsg}}
    </div>
  </div>
</template>

<script>
  export default {
    props: {
      btnStyle: {
        width: {type: String, default: '308px'},
        height: {type: String, default: '48px'}
      },
      btnMsg: {
        type: String,
        required: true,
        default: ''
      }
    },
    data() {
      return {
        btnWidth: '308px',
        btnHeight: '48px'
      }
    },
    computed: {
      btnStyleComputed() {
        let {btnStyle} = this.$props
        if (btnStyle === undefined) {
          btnStyle = {}
          btnStyle['height'] = this.btnHeight
          btnStyle['width'] = this.btnWidth
        }
        if (btnStyle.hasOwnProperty('height')) {
          btnStyle['height'] = btnStyle['height'].split('px')[0] - 30 + 'px'
        } else {
          btnStyle['height'] = this.btnHeight.split('px')[0] - 30 + 'px'
        }
        if (btnStyle.hasOwnProperty('width')) {
          btnStyle['width'] = btnStyle['width']
        } else {
          btnStyle['width'] = this.btnWidth
        }

        btnStyle[`line-height`] = btnStyle.height
        return btnStyle
      }
    },
    methods: {
      btnClick() {
        this.$emit('buttonClick', this.name)
      },
      buttonCommonMouseOver($event) {
        $event.currentTarget.className = 'buttonCommonClass buttonCommonMouseOverClass'
      },
      buttonCommonMouseOut($event) {
        $event.currentTarget.className = 'buttonCommonClass'
      }
    }
  }
</script>

<style>
  .buttonCommonClass {
    background: rgba(0, 153, 68, 1);
    opacity: 0.45;
    text-align: center;
    padding: 15px 0;
    font-size: 18px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: rgba(220, 220, 220, 1);
    cursor: pointer;
  }

  .buttonCommonMouseOverClass {
    color: #111111;
    background: #30ff10;
  }
</style>
